package com.pulp.production.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.pulp.production.service.ProductionInfoService;

public class PaperTotalAction<ProductionInfo> extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(PaperTotalAction.class);

	private String errorCode = "";

	private List paperTotalYearList = null;
	private List paperTotalMonthList = null;
	private List PaperTotalDateList = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		PaperTotalAction.logger = logger;
	}

	/**
	 * @return the paperTotalYearList
	 */
	public List getPaperTotalYearList() {
		return paperTotalYearList;
	}

	/**
	 * @param paperTotalYearList the paperTotalYearList to set
	 */
	public void setPaperTotalYearList(List paperTotalYearList) {
		this.paperTotalYearList = paperTotalYearList;
	}

	/**
	 * @return the paperTotalMonthList
	 */
	public List getPaperTotalMonthList() {
		return paperTotalMonthList;
	}

	/**
	 * @param paperTotalMonthList the paperTotalMonthList to set
	 */
	public void setPaperTotalMonthList(List paperTotalMonthList) {
		this.paperTotalMonthList = paperTotalMonthList;
	}

	/**
	 * @return the paperTotalDateList
	 */
	public List getPaperTotalDateList() {
		return PaperTotalDateList;
	}

	/**
	 * @param paperTotalDateList the paperTotalDateList to set
	 */
	public void setPaperTotalDateList(List paperTotalDateList) {
		PaperTotalDateList = paperTotalDateList;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public PaperTotalAction() {}

	public String excute() throws Exception {
		// 윤년 확인
		// for (int i = 2000; i <= 2012; i++) {
		// if (DateUtil.isLeapYear(i)) {
		// System.out.println(i + " isLeapYear");
		// }
		// }
		try {

			HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			ProductionInfoService productionInfoService = (ProductionInfoService) wac.getBean("productionInfoService");
			paperTotalYearList = productionInfoService.getPaperTotalYear();
			paperTotalMonthList = productionInfoService.getPaperTotalMonth();
			PaperTotalDateList = productionInfoService.getPaperTotalDate();
			request.setAttribute("paperTotalYearList", paperTotalYearList);
			request.setAttribute("paperTotalMonthList", paperTotalMonthList);
			request.setAttribute("PaperTotalDateList", PaperTotalDateList);
			// List loginList = orgnizationInfoService.getUserInfo();

		} catch (Exception ex) {
			REQUEST_RESULT = "FAILED";
			ex.printStackTrace();
		}
		return REQUEST_RESULT;
	}
}